package com.example.controller;

import com.example.dto.base.Result;
import com.example.dto.dataresource.ConnectDto;
import com.example.service.DataResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * <p>
 * 数据库源表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2023-02-28
 */
@RestController
@RequestMapping("/dataResource")
@Api(value = "DataResourceController",tags = "数据源的控制层")
public class DataResourceController {

    @Autowired
    private DataResourceService dataResourceService;

    @ApiOperation(value = "连通测试（表单左下角）")
    @PostMapping("/modalConnMysql")
    public Result<Boolean>  modalConnMysql(@RequestBody @Validated ConnectDto sqlInfo){
        HashMap<String, Object> map = dataResourceService.modalConnMysql(sqlInfo);
        return Result.successData((Boolean) map.get("status"), (String) map.get("message"));
    }

    @ApiOperation(value = "连通测试（表单左下角）")
    @GetMapping("/tableConnMysql/{id}")
    public Result<Boolean>  tableConnMysql(@PathVariable("id") Integer id){
        HashMap<String, Object> map = dataResourceService.tableConnMysql(id);
        return Result.successData((Boolean) map.get("status"), (String) map.get("message"));
    }
}
